<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%	
	//获取项目名
	String path = request.getContextPath();
	//获取tomcat 协议+地址+端口号+ 获取项目名
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	//out.println(basePath);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>网站后台管理模版</title>
<link rel="stylesheet" type="text/css"
	href="<%=basePath %>background/static/admin/layui/css/layui.css" />
<link rel="stylesheet" type="text/css"
	href="<%=basePath %>background/static/admin/css/admin.css" />
<script src="<%=basePath %>jquery-3.5.1.js"></script>
<script
	src="<%=basePath %>bootstrap/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<link rel="stylesheet"
	href="<%=basePath %>bootstrap/bootstrap-3.3.7-dist/css/bootstrap.css">
<script src="<%=basePath %>js/content.js"></script>
<link rel="stylesheet" href="../css/sweetalert.css">
<script src="../js/sweetalert-dev.js"></script>
</head>
<body>

	<div class="wrap-container">
		<!--  -->
		<form class="layui-form" style="width: 90%; padding-top: 20px;">
			<div class="layui-form-item">
				<label class="layui-form-label">类别：</label>
				<div class="layui-input-block">
					<select id="kind" name="category" lay-verify="required">
						<option value=""></option>
						<option value="0">HTML模板</option>
						<option value="1">CSS特效</option>
						<option value="2">jQuery代码</option>
					</select>
				</div>

			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">资源名称：</label>
				<div class="layui-input-block">
					<input id="name" type="text" name="title" required
						lay-verify="required" placeholder="请输入名称" autocomplete="off"
						class="layui-input">
				</div>

			</div>

			<div class="layui-form-item">
				<label class="layui-form-label">上传资源：</label>

				<div class="layui-input-block">
					<form action="/resourceSharing/UploadServlet" method="post"
						enctype="multipart/form-data">

						<input type="file" name="title" autocomplete="on"
							class="layui-input"> <input name="mark" value="addRs2"
							type="hidden"> <input type="hidden" id="userId-2"
							name="userId-2" value=""> <input type="hidden"
							id="rsCategory-2" name="rsCategory-2" value=""> <input
							type="hidden" id="rsName-2" name="rsName-2" value=""> <input
							type="hidden" id="rsDes-2" name="rsDes-2" value="">
						<!--       							<input type="submit" value="上传" />
 -->
					</form>
					<!-- <form action="/resourceSharing/UploadServlet" method="post" enctype="multipart/form-data">
						<table width="600px">
							<tr>
								<td>上传者</td>
								<td><input type="text" name="name" /></td>
							</tr>
							<tr>
								<td>上传文件</td>
								<td><input type="file" name="myfile" /></td>
							</tr>
							<tr>
								<td colspan="2"><input type="submit" value="上传" /></td>
							</tr>
						</table>
					</form> -->

				</div>

			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label">资源描述</label>
				<div class="layui-input-block">
					<textarea id="desc" name="desc" placeholder="请输入内容"
						class="layui-textarea"></textarea>
				</div>
			</div>

			<div class="">
				<div class="layui-input-block">
					<!--lay-submit lay-filter="formDemo"  -->
					<button id="sub" class="layui-btn layui-btn-normal">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript" charset="utf-8">
		
			$("#sub").click(function(){
				var userId = ${user.userId};
				var kind_temp = $("#kind").val();
				var rsCategory = null;
				if("0"==kind_temp){
					var rsCategory = "HTML模板";
				}else if("1"==kind_temp){
					var rsCategory = "CSS特效";
				}else if("2"==kind_temp){
					var rsCategory = "jQuery代码";
				}
				var rsName = $("#name").val();
				var rsDes = $("#desc").val();
				console.log(userId,kind_temp,rsCategory,rsName,rsDes);
				document.getElementById("userId-2").value = userId;
				document.getElementById("rsCategory-2").value = rsCategory;
				document.getElementById("rsName-2").value = rsName;
				document.getElementById("rsDes-2").value = rsDes;
				var userId2 = $("#userId-2").val();
				var rsCategor2 = $("#rsCategory-2").val();
				var rsName2 = $("#rsName-2").val();
				console.log(userId2,rsCategor2,rsName2);
				console.log($("#upload").submit());
				$("#upload").submit();
				
				console.log("还能输出吗？");
				
				
				if(rsCategory==null || rsCategory==""){
					alert("请选择资源类别！");
					return;
				}
				
				if(rsName==null || rsName==""){
					alert("请输入资源名称！");
					return;
				}
				
				if(rsDes==null || rsDes==""){
					alert("请输入对资源的描述！");
					return;
				}
				
				$.ajax({
					url:"<%=basePath %>backgroundServlet",
					type:"get",
					data:"mark=addRs&userId="+userId+"&rsCategory="+rsCategory+"&rsName="+rsName+"&rsDes="+rsDes,
					dataType:"json",
					success:function(mes){
						console.log("mes:"+mes)
						if(mes==true){
							swal("添加成功！",rsName,"success")
							window.location.href = "<%=basePath %>backgroundServlet?mark=bShowRs&userId=${user.userId}&manage=${user.manage}";
							
						}else{
							alert("添加失败！");
							return;
						}
					}
				});
				
				
			})		
		</script>
	<script src="<%=basePath %>background/static/admin/layui/layui.js"
		type="text/javascript" charset="utf-8"></script>
	<script>
			//Demo
			layui.use(['form'], function() {
				var form = layui.form();
				form.render();
				//监听提交
				form.on('submit(formDemo)', function(data) {
					layer.msg(JSON.stringify(data.field));
					return false;
				});
			});
		</script>
</body>

</html>